package cn.lili.modules.order.order.entity.dto;

import cn.hutool.core.text.CharSequenceUtil;
import cn.lili.common.vo.PageVO;
import cn.lili.modules.order.order.entity.enums.OrderItemAfterSaleStatusEnum;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.Serial;


/**
 * @author paulG
 * @since 2022/6/28
 **/

@EqualsAndHashCode(callSuper = true)
@Data
public class OrderItemFlowSearchParams extends PageVO {

    @Serial
    private static final long serialVersionUID = 4552818804596790565L;

    private String distributionId;

    private String userId;

    private String orderSn;

    private String orderItemSn;

    private String orderFlowSn;

    private String goodsId;

    private String skuId;

    /**
     * @see OrderItemAfterSaleStatusEnum
     */
    private String afterSaleStatus;


    public <T> QueryWrapper<T> getQueryWrapper() {
        QueryWrapper<T> queryWrapper = new QueryWrapper<>();
        if (CharSequenceUtil.isNotEmpty(distributionId)) {
            queryWrapper.eq("oif.distribution_id", distributionId);
        }
        if (CharSequenceUtil.isNotEmpty(userId)) {
            queryWrapper.eq("oif.user_id", userId);
        }
        if (CharSequenceUtil.isNotEmpty(orderSn)) {
            queryWrapper.eq("oif.order_sn", orderSn);
        }
        if (CharSequenceUtil.isNotEmpty(orderItemSn)) {
            queryWrapper.eq("oif.order_item_sn", orderItemSn);
        }
        if (CharSequenceUtil.isNotEmpty(orderFlowSn)) {
            queryWrapper.eq("oif.order_flow_sn", orderFlowSn);
        }
        if (CharSequenceUtil.isNotEmpty(goodsId)) {
            queryWrapper.eq("oif.goods_id", goodsId);
        }
        if (CharSequenceUtil.isNotEmpty(skuId)) {
            queryWrapper.eq("oif.sku_id", skuId);
        }
        if (CharSequenceUtil.isNotEmpty(afterSaleStatus)) {
            queryWrapper.eq("oi.after_sale_status", afterSaleStatus);
        }

        if(CharSequenceUtil.isNotEmpty(getSort())) {
            queryWrapper.orderByDesc(getSort());
        }

        return queryWrapper;
    }
}
